/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/threads
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AECriticalSection.h
// Author:		Gianluca Belardelli
// Date:		08/10/2013
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AECRITICALSECTION_H_
#define _AECRITICALSECTION_H_

class AE_COREDLLIMPEXP AECriticalSection
{
// Members
protected:
	AECRITICALSECTION	m_csSection;

// Methods
	AE_DECLARE_NON_COPYABLE( AECriticalSection );

public:
	AE_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( TOBEDEFINED, AECriticalSection );

	/// Init a critical section with spin count.
	/// Read MSDN help of InitializeCriticalSectionAndSpinCount for details.
	///
	/// In short: positive spinCount value results in threads doing busy waiting and is good
	/// when you know that the critical section will only be locked for a short period of time.
	/// zero value causes the thread to immediately go back to the system when waiting.
	AECriticalSection( AEUINT32 nSpinCount = 0 );

	/// Quit a critical section
	~AECriticalSection( void );

	/// Lock a critical section
	void Enter( void );

	/// Unlock a critical section
	void Leave( void );
};

#endif // _AECRITICALSECTION_H_

